<template>
  <div class="ele-body">

    <el-card class="box-card">
      <div slot="header">
        <div class="flex-between">
          <div>
            <div>更新日志</div>
            <span>记录往期你所更新的内容</span>
          </div>
          <div class="flex-start-center">

            <el-button v-if="flag"
                       type="primary"
                       :loading="loadingUpdata"
                       @click="updata()">
              更新
            </el-button>
          </div>
        </div>
      </div>

      <div style="height: 546px;overflow-x: auto;overflow-x: hidden;"
           class="flex-start borderBottom"
           v-for="(item, index) in logList"
           :key="index">
        <div class="versionInformation flex-column">
          <div>
            <span>版本信息</span>
          </div>
          <div class="versionNumber">
            {{ item.version_number }}
          </div>
        </div>
        <div class="upDataLog">
          <div>
            <span>更新时间:</span> {{ formattedDate(item.create_time) }}
          </div>
          <div class="flex-start">
            <span>更新内容:</span>
            <div v-html="item.remarks"></div>
          </div>
        </div>
      </div>
      <!-- <el-pagination background
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :page-size="10"
                     layout="prev, pager, next"
                     :total="total">
      </el-pagination> -->
    </el-card>
  </div>
</template>
  <script>

import moment from 'moment';
import { isNew, index } from '@/api/version/index';
import { versionList } from '@/api/version/index'
export default {
  name: 'updateVersion',
  components: {},
  data () {
    return {
      // 当前版本
      currentVersion: '',

      //   最新版本
      latestVersion: '',
      //   标记
      sign: '',
      //   当前标记信息
      signMsg: '',
      latestVersionBoolen: true,
      //   到期时间
      endDate: '',
      loading: false,
      form: {
        // 取平台的appid
        appid: '',
        // 取平台的域名
        realmName: '',
        id: '',

        softwareIdentifying: 'wjyk_massage',
        updateFlag: '2'
      },
      params: {

        page: 1,
        limit: 10000
      },
      //   当前总数
      total: null,
      //
      //   更新列表
      upDataList: [],
      //   日记更新列表
      logList: [],
      pcGzhUrl: '',
      versionUrl: '',
      flag: null,
      loadingUpdata: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },
    // 时间格式化
    formattedDate () {
      return (params) => {
        const currentDate = moment(params);
        const formattedDate = currentDate.format('YYYY-MM-DD ');
        return formattedDate;
      };
    }
  },
  activated () {
    this.init();
    this.isNewFn()
  },
  methods: {
    async updata () {
      this.loadingUpdata = true
      const res = await index();
      console.log(res);
      if (res.code == 0) {
        this.loadingUpdata = false
        this.$message.success(res.message)
        this.$router.go(0);
      } else {
        this.loadingUpdata = false
        this.$message.error(res.message)
      }
      // if (res.code == 0) {

      // }
    },
    async isNewFn () {
      const res = await isNew();
      console.log(res);
      if (res.code == 0) {
        this.flag = res.data.flag;
        // if (this.flag) {
        // }
      } else {
        this.$message.error(res.message)
      }
    },
    async init () {




      //   更新列表
      const upDataList = await versionList(this.params);


      this.logList = upDataList.data;




    },



    async versionUpload () {
      // window.open(this.versionUrl, '_self');

      //   调用修改接口
      //   const res = await platformSettingsModify({
      //     versionNumber: this.latestVersion,
      //     id: this.form.id
      //   })
      //   console.log(res)

      this.loading = true;
      const res = await fileDownload({
        // pcGzhUrl: this.pcGzhUrl,
        versionUrl: this.versionUrl,
        versionNumber: this.latestVersion
      });
      if (res == '操作失败') {
        this.loading = false;
        this.$message.error('更新失败');
        // 修改当前的版本号

        // const data = {
        //   versionNumber: this.latestVersion
        // };
        // 刷新页面
        // this.$router.go(0);
      } else {
        this.loading = false;
        this.$message.success(res);
        // 修改当前的版本号

        // const data = {
        //   versionNumber: this.latestVersion
        // };
        // 刷新页面
        this.$router.go(0);
      }
    },
    handleSizeChange (val) {
      this.params.page = val;
      this.init();
    },
    handleCurrentChange (val) {
      this.params.page = val;
      this.init();
    }
  }
};
  </script>
  <style lang="less" scoped>
i {
  font-style: normal;
}
span {
  color: #999;
  font-size: 12px;
}
.versionInformation {
  color: #000;
  .versionNumber {
    color: #1e6ceb;
    margin-top: 10px;
  }
}
.borderBottom {
  padding: 10px 0;
  border-bottom: 1px solid #f5f6fb;
}

.el-button {
  span {
    color: #fff;
  }
}
.upDataLog {
  margin-left: 36px;

  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.currentVersion {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  border-bottom: 1px solid #f5f6fb;
  padding-bottom: 5px;
}
.newVersion {
  height: 80px;
  line-height: 80px;
  border-bottom: 1px solid #f5f6fb;
}
.expirationTime {
  height: 80px;
  line-height: 80px;
}
</style>
  